/**
 * Created by Adam on 2017/5/16.
 */
import UserList from '../components/UserList'
import { connect } from 'react-redux'
import { toggleGender } from '../actions'

const getVisibleUsers = (state, filter) => {
    switch (filter) {
        case 'ALL':
            return state
        case 'Female':
            return state.filter(t => t.gender === 'Female')
        case 'Male':
            return state.filter(t => t.gender === 'Male')
        default:
            return state
    }

}
const mapStateToProps = (state, ownProps) => {
    return {
        users: getVisibleUsers(state.users, ownProps.filter)
    }
}

const mapDispatchToProps = (dispatch) => ({
    onUserClick: (id) => {
        dispatch(toggleGender(id))
    }
})

const VisibleUserList = connect(
    mapStateToProps,
    mapDispatchToProps
)(UserList)

export default VisibleUserList
